<template>
  <div id="assetsHead">
    <van-nav-bar
        :border="false"
        :title="title"
        :left-arrow="showLeft"
        @click-left="onClickLeft">
      <template #right>
        <slot></slot>
      </template>
    </van-nav-bar>
  </div>
</template>

<script>
export default {
  name: "assets-head",
  props: {
    title: {
      type: String,
      default: ''
    },
    goHome: {
      type: Boolean,
      default: false
    },
    goAssetsCenter: {
      type: Boolean,
      default: false
    },
    goPerpetualContract: {
      type: Boolean,
      default: false
    },
    showLeft: {
      type: Boolean,
      default: true
    },
    backFunc: {
      type: Function,
    },
    clickFunc: {
      type: Function,
    },
  },
  methods: {
    onClickLeft() {
      if (this.goHome) {
        this.$router.push('/');
      } else if (this.goAssetsCenter) {
        this.$router.push('/assetsCenter/assets');
      }else if (this.goPerpetualContract){
        this.$router.go(-2);
      } else if (this.backFunc) {
        this.backFunc()
      } else if (this.clickFunc) {
        this.clickFunc()
      } else {
        //如果没有浏览记录 就返回主页
        if (window.history.length > 1) {
          this.$router.go(-1)
        } else {
          this.$router.push('/')
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
